package com.shrikanthravi.customnavigationdrawer2.utils;

import ohos.agp.window.service.Display;
import ohos.agp.window.service.DisplayManager;
import ohos.app.Context;

public class JUtils {
    private static long mLastClickTime = 0L;
    private static final long timeInterval = 1000L;


    /**
     * 防止重复点击
     *
     * @param callBack 回调事件
     */
    public static void preventRepeatClick(CallBack callBack) {
        long nowTime = System.currentTimeMillis();
        if (nowTime - mLastClickTime > timeInterval) {
            // 单次点击事件
            callBack.callBack();
            mLastClickTime = nowTime;
        }
    }

    public interface CallBack {
        void callBack();
    }


    /**
     * 尺寸转换 vp 2 px
     *
     * @param mContext 上下文
     * @param vp       vp值
     * @return px值
     */
    public static float vp2px(Context mContext, float vp) {
        Display display = DisplayManager.getInstance().getDefaultDisplay(mContext).get();
        float dpi = display.getAttributes().densityPixels;
        return vp * dpi + 0.5f * (vp >= 0 ? 1 : -1);
    }

    /**
     * 判断内容是否为空
     * @param str 内容
     * @return 结果
     */
    public static boolean isEmpty(String str){
        return str == null || str.length() == 0;

    }
}
